import { defHttp } from '/@/utils/http/axios';
import { CategoryIdsModel } from './model/categoryModel';
import { AttrListModel, AttrModel } from './model/attrModel';

// 定义请求地址的枚举
enum Api {
  GetAttrList = '/admin/product/attrInfoList',
  AddOrUpdateAttr = '/admin/product/saveAttrInfo',
}

/**
 * 获取属性列表
 * @param categoryIds 三级分类id对象
 * @returns
 */
export const getAttrListApi = ({
  category1Id,
  category2Id,
  category3Id,
}: CategoryIdsModel<number>) => {
  return defHttp.get<AttrListModel>({
    url: Api.GetAttrList,
    params: `/${category1Id}/${category2Id}/${category3Id}`,
  });
};

/**
 * 添加或更新属性
 * @param data 属性
 * @returns
 */
export const addOrUpdateAttrApi = (data: AttrModel) => {
  return defHttp.post<null>({
    url: Api.AddOrUpdateAttr,
    data,
  });
};
